package com.example.backend.mapper;

import com.example.backend.entity.UserAdress;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;

@Repository
public interface UserAdressMapper {

    @Delete("delete from user_adress where id = #{id}")
    int deleteById(String id);

    @Insert("insert into user_adress(user_id,name,address,phone,region,is_default) values ( #{user_id},#{name},#{address}, #{phone}, #{region},#{is_default})" )
    int insert(UserAdress record);

    @Update("update user_adress set user_id = #{user_id},name = #{name} , address = #{address} ,  phone = #{phone} , region = #{region},is_default=#{is_default} where id = #{id}")
    int update(UserAdress record);

     @Select("select id,user_id,name,address,phone,region,is_default from user_adress where id = #{id}")
     UserAdress selectById(Integer id);

     @Select("select id,user_id,name,address,phone,region,is_default from user_adress where user_id = #{userId}")
     ArrayList<UserAdress> selectByUserId(Integer userId);

     @Select("select  id,user_id,name,address,phone,region,is_default from  user_adress")
     ArrayList<UserAdress> selectAll();

    @Update("update user_adress set is_default=0 where user_id = #{user_id}")
    int setNoDefault(UserAdress userAdress);
}
